define(['jquery', 'text!./template/myHeader.html', 'underscore', 'yf'], function($, myHeaderTpl, _, yf) {
	var common = {
		init: function() {
			this.loadHeader();
			this.slideModule();
		},
		loadHeader: function() {
			var url = './data/myHeader.json';
			yf.ajax({
				type: "get",
				url: url,
				async: true,
				success: function(data) {
					var data = data.data;
					var html = $(myHeaderTpl).html();
					var fn = _.template(html);
					var tpl = fn({
						result: data
					});

					$('.salerInfo').html(tpl);
					$('.goBackBtn').on('click', function() {
						yf.goBack_WP();
					})
				}
			});
		},
		slideModule: function() {
			//touchmove一定要按下去再移动
			var view  = $('.view');
			var myBody = $('.body');
			var startX = 0,
				endX = 0,
				acTiveLeft = 0,
				nextLeft = 0,
				screenWidth = $('.view').width(),
				next = null,
				animateIs = false;

			view.on('touchmove','.body', function(e) {
				var _myBody = $(this);
				var _touch = e.originalEvent.targetTouches[0];
				var x = _touch.pageX;
				if(startX == 0) {
					startX = x;
				}
				acTiveLeft = x - startX;
				_myBody.css('left', acTiveLeft + 'px');
				if(_myBody.next()) {
					next = _myBody.next();
					next.css('display', 'block').css('left', screenWidth + acTiveLeft + 'px');
				}

			});
			view.on('touchend','.body', function(e) {
				var _myBody = $(this);
				var _touch = e.originalEvent.changedTouches[0];
				var _x = _touch.pageX;
				endX = _x;
				if(acTiveLeft < -(screenWidth / 2)) {
					if(next.length != 0) {
						var left = screenWidth + acTiveLeft;
						_myBody.add(next).animate({
							left: "-=" + left + "px"
						}, function() {
							//这里会执行两遍,因为上面有add,两个元素一起运动
							if(!animateIs){
								animateIs = true;
								$('.tap .tapActive').next().click();
								setTimeout(function() {
									_myBody.css('left', '0px');
								}, 500);
							}
						});
					}else{
						_myBody.animate({
							left: "-" + screenWidth + "px"
						}, function() {
							$('.tap .tapActive').next().click();
							setTimeout(function() {
								_myBody.css('left', '0px');
							}, 500);
						});
					}
				} else {
					_myBody.animate({
						left: "0px"
					});
				}
			})

		}
	}
	return common;
});